
from chaotic import chaotic
from mbg import join, bottom, top, assign, iota

succ = {1: set([2]),
        2: set([3]),
        3: set([4, 6]),
        4: set([5]),
        5: set([3]),
        6: set([7]),
        7: set()
        }

tr = {(1,2): lambda ng: assign(ng, 'x', ('6', ())),
      (2,3): lambda ng: assign(ng, 'y', ('1', ())),
      (3,4): lambda ng: ng,
      (3,6): lambda ng: ng,
      (4,5): lambda ng: assign(ng, 'y', ('*', (('y',()), ('x',())))),
      (5,3): lambda ng: assign(ng, 'x', ('-', (('x',()), ('1',())))),
      (6,7): lambda ng: assign(ng, 'z', ('y', ())),
      }

tr_txt = {(1,2): "x = 6;",
          (2,3): "y = 1;",
          (3,4): "while (x > 0) do:",
          (3,6): "while (x > 0) do (end while)",
          (4,5): "y = y * x;",
          (5,3): "x = x - 1;",
          (6,7): "z = y;",
          }

chaotic(succ, 1, iota, join, bottom, tr, tr_txt, "ng_prog2.png")

#1. x = 6;
#2. y = 1;
#3. while (x > 0):
#4.    y = y * x;
#5.    x = x - 1;
#6. z = y;